import Lang from '../libs/i18';
const Search = React.createClass({
    propTypes: {
        submit: React.PropTypes.func,
        placeholder: React.PropTypes.string,
    },
    componentDidMount(){

    },
    getInitialState(){ //default value
        return {
            submit: this.props.submit || function () {
            },
            kw: '',
            placeholder: Lang.search_placeholder
        }
    },
    valueChange(e){
        this.state.kw = e.target.value;
        this.state.kw.length || this.state.submit(this.state.kw)
    },
    keyDown(e){
        if (e.keyCode == 13) {
            this.state.submit(e.target.value)
        }
    },
    click(){
        this.state.submit(this.state.kw)
    },
    render(){
        return (
            <div className="input-group">
                <input
                    onKeyDown={this.keyDown}
                    onChange={this.valueChange}
                    placeholder={Lang.search_placeholder} className="form-control"
                    type="text"/>
                <span className="input-group-btn">
                    <button type="button" onClick={this.click} className="btn btn-default" style={{marginRight: '0'}}>
                        <i className="fa fa-search"></i>
                    </button>
                </span>
            </div>
        );
    }
})
export default  Search;